package com.jeecg.p3.system.config;

import com.jeecg.p3.system.interceptors.AccessSignInterceptor;
import com.jeecg.p3.system.interceptors.LoginInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.MultipartConfigElement;
import java.util.Arrays;
import java.util.List;

@Configuration
public class UploadConfiguration implements WebMvcConfigurer {
    private final static Logger log = LoggerFactory.getLogger(UploadConfiguration.class);

    private List<String> EXCLUDE_PATHS= Arrays.asList("/plug-in/**","/content/**","/profile/**","/system/*.do","/error");

    @Autowired
    UploadConfig uploadConfig;
    @Autowired
    private LoginInterceptor loginInterceptor;
    @Autowired
    private AccessSignInterceptor accessSignInterceptor;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedOrigins("*").allowCredentials(true).allowedMethods("*").maxAge(3600);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /** 图片传路径 */
        log.info("uploadConfig: " + uploadConfig.getUploadPath());
        registry.addResourceHandler("profile/**").addResourceLocations("file:" + uploadConfig.getUploadPath());
    }
}
